package controlers;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import models.Banda;
import models.Usuario;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class LoginChecker extends ActionSupport
{
	private String username, password, nome, adress;
	private Integer age;
	List<String> bands;
	@SuppressWarnings("unchecked")
	@Override
	public String execute()
	{
		Map<String,Usuario> cadastros;
		cadastros = (HashMap<String,Usuario>)ActionContext.getContext().getApplication().get("cad");
		if(cadastros==null) {
			return "fail";
		}
		if(cadastros.containsKey(username))
		{
			Usuario temp = cadastros.get(username);
			if(temp.getSenha().equals(password))
			{
				ActionContext.getContext().getSession().put("login", temp);
				bands = new LinkedList<String>();
				for(Banda x : temp.getBandasFav())
				{
					bands.add(x.getNome());
				}
				return "sucess";
			}
		}
		return "fail";
	}
	public List<String> getBands() {
		return bands;
	}
	public void setBands(List<String> bands) {
		this.bands = bands;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}
	public String getAdress() {
		return adress;
	}
	public void setAdress(String adress) {
		this.adress = adress;
	}
	public Integer getAge() {
		return age;
	}
	public void setAge(Integer age) {
		this.age = age;
	}
}
